package com.zhijiaoyun.common;

import java.util.HashMap;
import java.util.Map;

/**
 * @author shisfish
 * @date 2017/12/5
 */
public class ResponseUtils {

    public static final int CAPACITY_2 = 2;
    public static final int CAPACITY_3 = 3;
    public static final int CAPACITY_4 = 4;
    public static final int CAPACITY_5 = 5;
    public static final int CAPACITY_6 = 6;

    public static final String CODE = "code";
    public static final String MESSAGE = "message";
    public static final String DATA = "data";

    public static final int CODE_SUCCESS = 0;
    public static final String MESSAGE_SUCCESS = "操作成功";

    public static final int CODE_TOKEN_LOST = 301;
    public static final String MESSAGE_TOKEN_LOST = "token过期";

    public static final int CODE_AUTHORITY_LOST = 302;
    public static final String MESSAGE_AUTHORITY_LOST = "您没有该权限！";

    public static final int CODE_LOGIN_ERROR = 303;
    public static final String MESSAGE_LOGIN_ERROR = "用户名或密码错误";

    public static final int CODE_OLD_PASSWORD_ERROR = 304;
    public static final String MESSAGE_OLD_PASSWORD_ERROR = "原密码错误";

    public static final int CODE_ADD_SHOPPING_CART_ORDER_ERROR = 305;

    public static final int CODE_USER_LOST = 402;
    public static final String MESSAGE_USER_LOST = "用户不存在";

    public static final int CODE_SCHOOL_LOST = 403;
    public static final String MESSAGE_SCHOOL_LOST = "学校不存在";

    public static final int CODE_COURSE_LOST = 404;
    public static final String MESSAGE_COURSE_LOST = "课程不存在";

    public static final int CODE_LESSON_LOST = 404;
    public static final String MESSAGE_LESSON_LOST = "课时不存在";

    public static final int CODE_ADMIN_ACCOUNT_EXIST = 416;
    public static final String MESSAGE_ADMIN_ACCOUNT_EXIST = "管理员账号已存在";
    public static final int CODE_AUTHORITY_EXIST = 418;
    public static final String MESSAGE_AUTHORITY_EXIST = "该角色已存在";

    public static final int CODE_FILE_UPLOAD_ERROR = 501;
    public static final String MESSAGE_FILE_UPLOAD_ERROR = "文件上传失败";

    public static final String LIST = "list";
    public static final String OBJ = "obj";
    public static final String PAGE = "page";

    public static final String MESSAGE_CHOOSE_AUTHORITY_TYPE = "请选择用户的角色";
    public static final int CODE_CONDITION_ERROR = 4004;
    public static final String MESSAGE_CONDITION_ERROR = "查询条件有误";

    public static Map<String, Object> responseLoginError() {
        return responseErrorMap(CODE_LOGIN_ERROR, MESSAGE_LOGIN_ERROR);
    }

    public static Map<String, Object> responseAuthorityLost() {
        return responseErrorMap(CODE_AUTHORITY_LOST, MESSAGE_AUTHORITY_LOST);
    }

    public static Map<String, Object> responseUserLost() {
        return responseErrorMap(CODE_USER_LOST, MESSAGE_USER_LOST);
    }

    public static Map<String, Object> responseAdminLost() {
        return responseErrorMap(CODE_USER_LOST, MESSAGE_USER_LOST);
    }

    public static Map<String, Object> responseCourseLost() {
        return responseErrorMap(CODE_LESSON_LOST, MESSAGE_LESSON_LOST);
    }

    public static Map<String, Object> responseLessonLost() {
        return responseErrorMap(CODE_LESSON_LOST, MESSAGE_LESSON_LOST);
    }

    public static Map<String, Object> responseConditionError() {
        return responseErrorMap(CODE_CONDITION_ERROR, MESSAGE_CONDITION_ERROR);
    }

    public static Map<String, Object> responseFileUploadError() {
        return responseErrorMap(CODE_FILE_UPLOAD_ERROR, MESSAGE_FILE_UPLOAD_ERROR);
    }

    public static Map<String, Object> responseErrorMap(int code, String message) {
        Map<String, Object> map = new HashMap<>(CAPACITY_2);
        map.put(CODE, code);
        map.put(MESSAGE, message);
        return map;
    }

    public static Map<String, Object> responseSuccessMap(Map<String, Object> map) {
    	Map<String, Object> returnMap = new HashMap<>();
    	returnMap.put(CODE, CODE_SUCCESS);
    	returnMap.put(MESSAGE, MESSAGE_SUCCESS);
        returnMap.put(DATA, map);
        return returnMap;
    }

    public static Map<String, Object> responseSuccessMap() {
        Map<String, Object> map = new HashMap<>(CAPACITY_2);
        map.put(CODE, CODE_SUCCESS);
        map.put(MESSAGE, MESSAGE_SUCCESS);
        return map;
    }

}
